package android.twitter.clientroid;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class UpdateTimeLineService extends Service
{
	public static final String TAG = UpdateTimeLineService.class.getSimpleName();
	private Timer timer;
	
	@Override
	public IBinder onBind(Intent intent)
	{
		return null;
	}

	@Override
	public void onCreate()
	{
		super.onCreate();
		//code to execute when the service is first created
		timer = new Timer("TweetCollectorTimer");
        timer.schedule(updateTask, 30*1000, 60 * 1000);
	}

	@Override
	public void onDestroy()
	{
		super.onDestroy();
		//code to execute when the service is shutting down
		timer.cancel();
        timer = null;
	}

	@Override
	public void onStart(Intent intent, int startid)
	{
		super.onStart(intent, startid);
		//code to execute when the service is starting up
	}
	
	private TimerTask updateTask = new TimerTask()
	{
        @Override
        public void run()
        {
			System.out.println("****************Updating timeline****************");
        	Intent updateIntent = new Intent(UpdateTimeLineService.this, TimeLineActivity.class);
        	updateIntent.addFlags(268435456);
        	startActivity(updateIntent);
        }
	};
	
	
	
}
